﻿using ClassLibrary1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #region 登录
       
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //var uid = tbUsersName.Text.Trim();
            //var pwd = tbPwd.Text.Trim();

            //var sql = string.Format("select * from Users where Username='{0}' and Password='{1}'", uid, pwd);
            //var dt= Dbhelper.GetDataTable(sql);

            ////判断输入的账号密码在数据库中是否存在
            //if (dt.Rows.Count==1)
            //{
            //    var row = dt.Rows[0];
            //    var IsActived = (bool)row.ItemArray[3];
            //    var IsDeleted = (bool)row.ItemArray[4];
                
            //    //判断账号是否被删除
            //    if (IsDeleted)
            //    {
            //        Response.Write("账号已被删除或注销,如有疑问，那就憋住吧");
            //    }
            //    else
            //    {  
            //        //判断账号是否启用
            //        if (IsActived)
            //        {
            //            Response.Write("登录成功");
            //            Response.Redirect("default.aspx");
            //        }
            //        else
            //        {
            //            Response.Write("你已获得十年大礼包,如有疑问，那就憋着吧");
            //        }
            //    }

                
            //}
            //else
            //{
            //    Response.Write("登录失败");
            //    Hint.Visible = true;
            //}

        }
        #endregion
        #region 注册
        protected void register_Click(object sender, EventArgs e)
        {

        }
        #endregion 
        protected void Lb1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            var uid = Lb1.UserName.Trim();
            var pwd = Lb1.Password.Trim();
            var sql = string.Format("select * from Users where Username='{0}' and Password='{1}'", uid, pwd);
            var dt = Dbhelper.GetDataTable(sql);

            //判断输入的账号密码在数据库中是否存在
            if (dt.Rows.Count == 1)
            {
                var row = dt.Rows[0];
                var IsActived = (bool)row.ItemArray[3];
                var IsDeleted = (bool)row.ItemArray[4];

                //判断账号是否被删除
                if (IsDeleted)
                {
                    Response.Write("账号已被删除或注销,如有疑问，那就憋住吧");
                }
                else
                {
                    //判断账号是否启用
                    if (IsActived)
                    {
                        Response.Write("登录成功");
                        Response.Redirect("default.aspx");
                    }
                    else
                    {
                        Response.Write("你已获得十年大礼包,如有疑问，那就憋着吧");
                    }
                }


            }
            else
            {
                Response.Write("登录失败");              
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("Register.aspx");
        }
    }
}